#include <iostream>
#include <sdfs/tracker/StatusTable.h>

#include <muduo/net/EventLoop.h>

using namespace std;
using namespace muduo;
using namespace muduo::net;

sdfs::tracker::StatusTable gStatusTable;

int main()
{
	
	cout<<"gStatusTable Size: "<< gStatusTable[0]->size() <<endl;
	{
	muduo::net::EventLoop loop;
	muduo::string name("conn");
	muduo::net::InetAddress localAddr(100);
	muduo::net::InetAddress peerAddr(200);	
	int sockfd = 10;
	TcpConnectionPtr conn(
		new TcpConnection(&loop, name, sockfd, localAddr, peerAddr));

	boost::shared_ptr<sdfs::protobuf::HeartBeat> heartbeat(
		new sdfs::protobuf::HeartBeat());

	heartbeat->set_id(0);
	heartbeat->set_free(100);
	heartbeat->set_capacity(1000);
	heartbeat->set_groupidx(0);

	muduo::Timestamp time = muduo::Timestamp::now();
	
	gStatusTable.updateConnection(conn, heartbeat, time);
	}

	cout<<"gStatusTable Size: "<< gStatusTable[0]->size() <<endl;
	{
	TcpConnectionPtr conn = gStatusTable[0]->getConnection();
	assert(conn != NULL);
	cout <<"conn: " << conn->peerAddress().toIpPort() << endl;

	gStatusTable.removeConnection(conn);
	}

	cout<<"gStatusTable Size: "<< gStatusTable[0]->size() <<endl;

}
